package me.zhengjie.modules.finace_taxation.rest;

import com.alibaba.fastjson.JSONObject;
import me.zhengjie.annotation.Log;
import me.zhengjie.base.PageInfo;
import me.zhengjie.modules.finace_taxation.domain.FtIndustryDetails;
import me.zhengjie.modules.finace_taxation.domain.FtIndustryDetailsFavorite;
import me.zhengjie.modules.finace_taxation.service.FtIndustryDetailsFavoriteService;
import me.zhengjie.modules.finace_taxation.service.dto.FtIndustryDetailsFavoriteDto;
import me.zhengjie.modules.finace_taxation.service.dto.FtIndustryDetailsFavoriteQueryParam;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

import java.util.Map;
import java.util.Set;

/**
* @author 杨荣森
* @date 2021-06-23
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "industry_details_favorite管理")
@RequestMapping("/api/ft/ftIndustryDetailsFavorite")
public class FtIndustryDetailsFavoriteController {

    private final FtIndustryDetailsFavoriteService ftIndustryDetailsFavoriteService;

    @GetMapping
    @Log("查询行业详情收藏")
    @ApiOperation("查询行业详情收藏")
//    @PreAuthorize("@el.check('ftIndustryDetailsFavorite:list')")
    public ResponseEntity query(FtIndustryDetailsFavoriteQueryParam query, Pageable pageable){
        return new ResponseEntity<>(ftIndustryDetailsFavoriteService.queryAll(query,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增行业详情收藏")
    @ApiOperation("新增行业详情收藏")
//    @PreAuthorize("@el.check('ftIndustryDetailsFavorite:add')")
    public ResponseEntity create(@Validated @RequestBody FtIndustryDetailsFavoriteDto resources){
        resources.setId("");
        return new ResponseEntity<>(ftIndustryDetailsFavoriteService.insert(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改行业详情收藏")
    @ApiOperation("修改行业详情收藏")
//    @PreAuthorize("@el.check('ftIndustryDetailsFavorite:edit')")
    public ResponseEntity update(@Validated @RequestBody FtIndustryDetailsFavoriteDto resources){
        ftIndustryDetailsFavoriteService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @Log("删除行业详情收藏")
    @ApiOperation("删除行业详情收藏")
//    @PreAuthorize("@el.check('ftIndustryDetailsFavorite:del')")
    public ResponseEntity delete(@RequestBody Set<String> ids) {
        ftIndustryDetailsFavoriteService.removeByIds(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @PostMapping("/queryByUserId")
    @Log("根据用户id查询行业收藏表")
    @ApiOperation("根据用户id查询行业收藏表")
    public JSONObject queryByUserId(@RequestBody Map<String, Object> map){
        JSONObject resObj = new JSONObject();
        PageInfo<FtIndustryDetails> pageInfo = ftIndustryDetailsFavoriteService.queryByUserId(map);
        resObj.put("data", pageInfo);
        resObj.put("success", true);
        resObj.put("message", "查询成功");
        resObj.put("code", 200);
        return resObj;
    }

    /*
    @Log("导出industry_details_favorite")
    @ApiOperation("导出industry_details_favorite")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('ftIndustryDetailsFavorite:list')")
    public void download(HttpServletResponse response, FtIndustryDetailsFavoriteQueryParam query) throws IOException {
        ftIndustryDetailsFavoriteService.download(ftIndustryDetailsFavoriteService.queryAll(query), response);
    }*/

    @PostMapping("/industryFavoriteFlag")
    @Log("判断用户是否收藏过改行业详情")
    @ApiOperation("判断用户是否收藏过改行业详情")
//    @PreAuthorize("@el.check('ftIndustryDetailsFavorite:add')")
    public ResponseEntity industryFavoriteFlag(@Validated @RequestBody FtIndustryDetailsFavoriteDto resources){
        return new ResponseEntity<>(ftIndustryDetailsFavoriteService.industryFavoriteFlag(resources),HttpStatus.CREATED);
    }

    @PostMapping("/cacelIndustryFavorite")
    @Log("取消行业详情收藏")
    @ApiOperation("取消行业详情收藏")
//    @PreAuthorize("@el.check('ftIndustryDetailsFavorite:add')")
    public ResponseEntity cacelIndustryFavorite(@Validated @RequestBody FtIndustryDetailsFavoriteDto resources){
        return new ResponseEntity<>(ftIndustryDetailsFavoriteService.cacelIndustryFavorite(resources),HttpStatus.CREATED);
    }

    @PostMapping("/addIndustryFavorite")
    @Log("收藏行业详情")
    @ApiOperation("收藏行业详情")
//    @PreAuthorize("@el.check('ftIndustryDetailsFavorite:add')")
    public ResponseEntity addIndustryFavorite(@Validated @RequestBody FtIndustryDetailsFavoriteDto resources){
        return new ResponseEntity<>(ftIndustryDetailsFavoriteService.addIndustryFavorite(resources),HttpStatus.CREATED);
    }

}
